import Vue from 'vue'
import Router from 'vue-router'

import { routes, errorRoutes } from './routes';



Vue.use(Router)

import { routerDefaultConf, routerBeforeEachFunc, routerAfterFunc } from '@/config/routerConf'

const createRouter = () => new Router({
  ...routerDefaultConf,
  routes: routes
})

const router = createRouter()

router.beforeEach(routerBeforeEachFunc)
router.afterEach(routerAfterFunc)

router.addRoutes(errorRoutes)

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

